#include <vector>
#include <iostream>

using namespace std;

// [9, 8, 1, 6, 2, 7]
//     ^i ^j
//       
int find_min(int i, vector<int> array) {
  int minValue = i;

  for (int j = i + 1; j < array.size(); ++j) {
    if (array[j] < array[minValue]) {
      minValue = j;
    }
  }

  return minValue;
}

void selectionSort(vector<int> &array) {
  for (int i = 0; i <= array.size() - 2; ++i) {
    int minPos = find_min(i, array);
    swap(array[i], array[minPos]);
  }

  return;
}

int main(int argc, char const *argv[])
{
  /* code */
  vector<int> v {9, 8, 2, 6, 5, 7};
  selectionSort(v);

  for (int n : v) {
    cout<<n<<" ";
  }

  cout<<endl;
  return 0;
}
